#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<cstring>
#include<set>
using namespace std;

int n;
set<int> u[55];
void f(int a, int b)
{
	int same = 0;
	set<int>::iterator it;
	for (it = u[a].begin(); it != u[a].end(); it++)
	{
		if (u[b].find(*it) != u[b].end())
		{
			same++;//用集合a中的值取b中找，如果相同，就++
		}
	}

	int sum = u[a].size() + u[b].size();//这是两个集合中的个数

	int nt = sum - same;//并集的个数

	printf("%.2lf\%\n", same*1.0 / nt * 100);
}

int main()
{
	cin >> n;
	int k, a, m;
	for (int i = 1; i <= n; i++)
	{
		cin >> k;
		for (int j = 0; j<k; j++)
		{
			cin >> a;
			u[i].insert(a);
		}
	}
	cin >> m;
	int b;
	for (int i = 0; i<m; i++)
	{
		cin >> a >> b;
		f(a, b);
	}

	return 0;
}


